package com.ajobs.project.transactiontest.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/**
 * Description
 * 全局拦截事务方法（@Transactional）
 *
 * @Around 运行时，注释掉 @Order(-1)时，事务会回滚（int i = 1/0;）；使用@Order(-1)，事务会提交。
 *
 * @author weijianxun
 */
@Component
@Aspect
@Order(-1)
public class AopTransaction {

    @Pointcut("@annotation(com.ajobs.project.transactiontest.anno.AopAnnotation)")
    public void transactionPointcut() {
        //
    }

    @Around("transactionPointcut()")
    public Object transactionAround(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        Object result = null;
        result = proceedingJoinPoint.proceed();
        // int i = 1 / 0;
        return result;
    }
}
